#include <iostream>
#include <thread>
#include <mutex>
using namespace std;

mutex mtx; // 创建一个互斥锁
void print(int num)
{
    lock_guard<std::mutex> lock(mtx); // 创建一个lock_guard 对象，使用互斥锁 mtx 进行保护
    cout << "Thread " << num << " is running." << endl;
}
int main() 
{
    thread t1(print, 1);
    thread t2(print, 2);

    t1.join();
    t2.join();

    return 0;
}